home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / WarpQuake / Src / chase.c < prev    next >
C/C++ Source or Header  |  2000-05-22  |  3KB  |  94 lines

  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  12.  
  13. See the GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. */
  20. // chase.c -- chase camera code
  21.  
  22. #include "quakedef.h"
  23.  
  24. cvar_t    chase_back = {"chase_back", "100"};
  25. cvar_t    chase_up = {"chase_up", "16"};
  26. cvar_t    chase_right = {"chase_right", "0"};
  27. cvar_t    chase_active = {"chase_active", "0"};
  28.  
  29. vec3_t    chase_pos;
  30. vec3_t    chase_angles;
  31.  
  32. vec3_t    chase_dest_angles;
  33.  
  34.  
  35. extern qboolean SV_RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f, vec3_t p1, vec3_t p2, trace_t *trace);
  36.  
  37. void Chase_Init (void)
  38. {
  39.     Cvar_RegisterVariable (&chase_back);
  40.     Cvar_RegisterVariable (&chase_up);
  41.     Cvar_RegisterVariable (&chase_right);
  42.     Cvar_RegisterVariable (&chase_active);
  43. }
  44.  
  45. void Chase_Reset (void)
  46. {
  47.     // for respawning and teleporting
  48. //    start position 12 units behind head
  49. }
  50.  
  51. void TraceLine (vec3_t start, vec3_t end, vec3_t impact)
  52. {
  53.     trace_t    trace;
  54.  
  55.     memset (&trace, 0, sizeof(trace));
  56.     SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1, start, end, &trace);
  57.  
  58.     VectorCopy (trace.endpos, impact);
  59. }
  60.  
  61. void Chase_Update (void)
  62. {
  63.     int        i;
  64.     float    dist;
  65.     vec3_t    forward, up, right;
  66.     vec3_t    dest, stop;
  67.     vec3_t    chase_dest;
  68.  
  69.     // if can't see player, reset
  70.     AngleVectors (cl.viewangles, forward, right, up);
  71.  
  72.     // calc exact destination
  73.     for (i=0 ; i<3 ; i++)
  74.         chase_dest[i] = r_refdef.vieworg[i] 
  75.         - forward[i]*chase_back.value
  76.         - right[i]*chase_right.value;
  77.     chase_dest[2] = r_refdef.vieworg[2] + chase_up.value;
  78.  
  79.     // find the spot the player is looking at
  80.     VectorMA (r_refdef.vieworg, 4096, forward, dest);
  81.     TraceLine (r_refdef.vieworg, dest, stop);
  82.  
  83.     // calculate pitch to look at the same spot from camera
  84.     VectorSubtract (stop, r_refdef.vieworg, stop);
  85.     dist = DotProduct (stop, forward);
  86.     if (dist < 1)
  87.         dist = 1;
  88.     r_refdef.viewangles[PITCH] = -atan(stop[2] / dist) / M_PI * 180;
  89.  
  90.     // move towards destination
  91.     VectorCopy (chase_dest, r_refdef.vieworg);
  92. }
  93.  
  94.